<template>
  <div class="about">
    <h1>This is an about page</h1>
    <button @click="connect">司机链接</button>
  </div>
  <div>
    <button @click="store.isDialogTrue()">关闭</button>
  </div>
</template>

<script setup>

import {useCounterStore} from '@/stores/counter'  // 根据你的文件路径修改

const store = useCounterStore()

function connect() {
  let websocket = null;

  if ('WebSocket' in window) {
    websocket = new WebSocket("ws://localhost:10005/websocket-vehicletrip/lanqiao123");
  } else {
    alert('不支持websocket')
  }

  //连接发生错误的回调方法
  websocket.onerror = function () {
    console.log("发生错误")
  };

  //连接成功建立的回调方法
  websocket.onopen = function (event) {
    console.log("打开链接")
  }

  //接收到消息的回调方法
  websocket.onmessage = function (event) {
    console.log(event.data)
    alert(event.data)

  }
}
</script>

<style>

</style>
